home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / utils / xpm-button.el < prev    next >
Encoding:
Text File  |  1995-08-31  |  23.8 KB  |  485 lines

  1. ;;; Create XPM text buttons under XEmacs (requires 19.12 or beyond)
  2. ;;; Copyright (C) 1995 Kyle E. Jones
  3. ;;;
  4. ;;; This program is free software; you can redistribute it and/or modify
  5. ;;; it under the terms of the GNU General Public License as published by
  6. ;;; the Free Software Foundation; either version 1, or (at your option)
  7. ;;; any later version.
  8. ;;;
  9. ;;; This program is distributed in the hope that it will be useful,
  10. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;;; GNU General Public License for more details.
  13. ;;;
  14. ;;; A copy of the GNU General Public License can be obtained from this
  15. ;;; program's author (send electronic mail to kyle@uunet.uu.net) or from
  16. ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  17. ;;; 02139, USA.
  18. ;;;
  19. ;;; Send bug reports to kyle@wonderworks.com
  20.  
  21. ;;; The sole interface function is xpm-button-create.
  22.  
  23. (provide 'xpm-button)
  24.  
  25. (defvar xpm-button-version "1.01"
  26.   "Version string for xpm-button.")
  27.  
  28. (defvar xpm-button-vertical-padding 3
  29.   "Number of pixels between the text and the top/bottom of the button.")
  30.  
  31. (defvar xpm-button-horizontal-padding 3
  32.   "Number of pixels between the text and the left/right edges of the button.")
  33.  
  34. (defvar xpm-button-font-pixel-lines
  35.   '(
  36. "    xx     xxxxxx     xxxx x xxxxxxx   xxxxxxxx xxxxxxxx   xxxx x  xxxx  xxxx xxxx    xxxx xxxx xxxx xxxx     xxxx   xxxx xxx    xxx   xxxxx   xxxxxxx    xxxxx    xxxxxxx    xxxx x xxxxxxxx xxxx  xxx xxxx   xxx xxxx xxxx xxx xxxx xxxx xxxx xxx xxxxxxxx         xxx                 xxx           xxx         xxx       xx   xx xxx      xxx                                                                 x                                                            xx     x   xxxx   xxxx    xxx   xxxxx   xxx  xxxxxx  xxxx   xxxx   x        xx     xxxx      x x   xxxx    xx   x       x      xxx       x      x x                                  xxxx   xx xxxx xx         xx x x                       x  xxxx  x     x                                                                                         "
  37. "    xx      xx  xx   xx   xx  xx   xx   xx   xx  xx   xx  xx   xx   xx    xx   xx      xx   xx   x    xx       xxx   xxx   xxx    x   xx   xx   xx   xx  xx   xx    xx   xx  xx   xx xx xx xx  xx    x   xx     x   xx   xx   x   xx   x    xx   x  xx   xxx          xx                  xx          xx x          xx       xx   xx  xx       xx                                                                xx                                                           x  x  xxx  xx  xx xx  xx   xxx   xxxx   x  xx xxxxxx xx  xx xx  xx x         xx   xx    x     x x  xx xxx  xx xxxx       x     xx  x    x x x   x   x                                 xx    xx    xx  xx        xx x x                       x xx  xx xx    x                                                                                         "
  38. "   x xx     xx  xx  xx     x  xx    xx  xx    x  xx    x xx     x   xx    xx   xx      xx   xx  x     xx       xxx   xxx   xxxx   x  xx     xx  xx   xx xx     xx   xx   xx  xx    x x  xx  x  xx    x   xx     x   xx   xx   x   xxx x     xx   x  x   xxx           xx                  xx          xx       xx   xx                xx       xx                                                                xx                                                          xx  xx  xx  xx  xx xx  xx  x xx   x     xx  xx x   x  xx   x xx  xx xx        xx  x  xxxx x  xxxxxx x  x   xx  x x       xxx    xx x      xxx   xx   xx                           x    xx    xx    xx  xx         x x x                       x xx  xx  x    x                                                                                         "
  39. "   x xx     xx  xx  xx     x  xx    xx  xx  x    xx  x x xx     x   xx    xx   xx      xx   xx x      xx       x xx x xx   x xxx  x  xx     xx  xx   xx xx     xx   xx   xx  xxxx    x  xx  x  xx    x    xx   x     xx x xx x     xxxx      xx x      xxx    xxxx    xx xx     xxx    xx xx    xxx  xxxxx  xxxx    xx xx   xxx  xxx  xx xxx   xx  xxx xx  xx   xxx xx     xxx   xxx xx     xx xx  xxx xx  xxxx xxxxx xxx xxx  xxxx xxx xxx xxxx xxx xxx xxx xxxx xxx xxxxxx xx  xx  xx      xx     xx  x xx   xxxx  xx        xx   xx x  xx  xx xx        xx  x x  xx x   x x   xx x   xx  x x  xx   x x     xx  xxx x x x  x     x                           x    xx    xx    xx  xx  xx xx x             xx    xx      xx     xx  xx   x                                                                                         "
  40. "  x   xx    xxxxx   xx        xx    xx  xxxxx    xxxxx   xx         xxxxxxxx   xx      xx   xxxxx     xx       x xx x xx   x  xxx x  xx     xx  xx  xx  xx     xx   xxxxx     xxxxx     xx     xx    x    xx   x     xx x xx x      xxx      xx x      xx     x  xx   xxx xxx xxx xx xxx xxx  xxx xx  xx   xx  xx   xxx xx   xx   xx  xx xx    xx   xxx xxx xx   xxx xx  xxx xxx  xxx xxx xxx xxx   xxxxx x   x  xx    xx  xx   xx   x   xx  xx   x   xx  x   xx   x  x  xxx xx  xx  xx     xx    xx   x  xx   x  xx xxxxx     xx   xxxx   xxxxx     xx  x xx x xx xx  x   x x    xxxx  xx x x  xx x xx xx   xxxx  x    x   xx     xx                xxxxxx    x    xx    x     xx   x  xx xx             xxx      xxx    x     xx    x   x                                                                                         "
  41. "  xxxxxx    xx   xx xx        xx    xx  xx  x    xx  x   xx   xxxx  xx    xx   xx      xx   xx xxx    xx       x xx x xx   x   xxxx  xx     xx  xxxxx   xx xx  xx   xx  xx      xxxx    xx     xx    x     xx x      xx x xx x     x xxx      xx      xxx      xxxx   xx   xx xx     xx   xx  xxxxxx  xx   xx  xx   xx  xx   xx   xx  xxxx     xx   xx  xx  xx   xx  xx  xx   xx  xx   xx xx   xx   xx    xxxx   xx    xx  xx    xx x     xx xxx x     xxx     xx x     xxx  xx  xx  xx    xx       xx x  xx      xx xx  xx   xx    x xxx     xx    xxxxxx xx x xx xx x  xxxxxx     xxx  xx  x xx  x x   x  x  xxxx         xx     xx xxxxxx                xxxxxxx xx   x      xx    x                 xxx          xxx xx    x      xx  x                                                                                         "
  42. " x     xx   xx   xx xx     x  xx    xx  xx    x  xx      xx    xx   xx    xx   xx  xx  xx   xx  xx    xx    x  x  xx  xx   x    xxx  xx     xx  xx      xxx  x xx   xx  xx   x    xx    xx     xx    x     xx x       xx   xx      x  xxx     xx     xxx   x xx  xx   xx   xx xx     xx   xx  xx      xx    xxxx    xx  xx   xx   xx  xx xx    xx   xx  xx  xx   xx  xx  xx   xx  xx   xx xx   xx   xx     xxxx  xx    xx  xx    xx x     xx xxx x     xxx     xx x    xxx   xx  xx  xx   x   x xx  xx xxxxxx xx  xx xx  xx   xx   x   xx xx  xx    x  xx     x  xx xx    x x    xx x x     x  xx  x       xx   xxx         xx     xx                xxxxxx    x    xx    x     xx   x                    xxx      xxx   x             x  x                                                                                         "
  43. " x     xx   xx   xx  xx   xx  xx   xx   xx   xx  xx       xx   xx   xx    xx   xx  xx  xx   xx  xxx   xx   xx  x  xx  xx   x     xx   xx   xx   xx       xx  xxx    xx   xxx xx   xx    xx     xxx  xx      xx        xx   xx     x    xx     xx    xxx   xx xx xxx   xx  xxx xxx xx xxx xxx  xxx xx  xx   x        xx  xx   xx   xx  xx  xx   xx   xx  xx  xx   xx  xx  xxx xxx  xxx xxx xxx xxx   xx    x   x  xx    xx xxx     xx       xx  xx     x  xx     xx    xxx  x  x  x   xx  xxxxxx xx  xx    xx  xx  xx xx  xx   xx   xx  xx xx  x            xx  x      x   x x    xx x x     x  xx x        xxx  xxxxx        x     x                           x    xx    xx    xx  xx  xx xx        xx     xx xx xx     x     xx      xx x                                                                                         "
  44. "xxx   xxxx xxxxxxx    xxxxx  xxxxxxx   xxxxxxxx xxxx       xxxx x  xxxx  xxxx xxxx  xxx    xxxx  xxx xxxxxxxx xxx xx xxxx xxx     x    xxxxx   xxxx       xxxxx    xxxx  xx  x xxxx    xxxx     xxxxx       xx        xx   xx    xxx  xxxx   xxxx   xxxxxxxx  xx xxx  x xxx     xxx    xx xxx   xxx  xxxx  xxxxxx  xxxx xxx xxxx  xx xxxx xxx xxxx xxxx xxx xxx xxxx xxx   xxx    xx xx     xx xx  xxxx   xxxx    xx    xx xxx    xx       xx  xx    xxx xxx    xx    xxxxxx   xx   xxxx xxxxxx  xxxx    xxxx  xxxx   xxxx    xx    xxxx   xxx             xx   xxxxxx    x x     xxxx     x    xx          xxxx  xx         xx   xx                           x    xx    xx    xx  xx  xx xx        xx        xx        x     xx       x x                                                                                         "
  45. "                                                                                                                                                              xxxx                                                                                                                                          xxxxxx                xx                                              xx           xx                                                               x                                                                                                                   x                                         x   x                                 xx    xx    xx  xx   x            x                                                                                                                             "
  46. "                                                                                                                                                               xx                                                                                                                                          x    xx                xx                                              xx           xx                                                            xxx                                                                                                                                                               x x           xxxxxxx                xxxx   xx xxxx xx   x            x                                                                                                                              "
  47. "                                                                                                                                                                                                                                                                                                            xxxxx                xx                                              xxxx         xxxx                                                           xx                                                                                                                                                                                                                                                                                                                                                                     "
  48.    )
  49.   "List of strings representing pixel lines for the button font.")
  50.  
  51. (defvar xpm-button-font-line-indices
  52.   '(("A" 0 10)
  53.     ("B" 11 19)
  54.     ("C" 20 28)
  55.     ("D" 29 38)
  56.     ("E" 39 47)
  57.     ("F" 48 56)
  58.     ("G" 57 66)
  59.     ("H" 67 77)
  60.     ("I" 78 82)
  61.     ("J" 83 90)
  62.     ("K" 91 100)
  63.     ("L" 101 109)
  64.     ("M" 110 121)
  65.     ("N" 122 132)
  66.     ("O" 133 142)
  67.     ("P" 143 151)
  68.     ("Q" 152 162)
  69.     ("R" 163 172)
  70.     ("S" 173 180)
  71.     ("T" 181 189)
  72.     ("U" 190 199)
  73.     ("V" 200 210)
  74.     ("W" 211 224)
  75.     ("X" 225 234)
  76.     ("Y" 235 243)
  77.     ("Z" 244 252)
  78.     ("a" 253 260)
  79.     ("b" 261 269)
  80.     ("c" 270 276)
  81.     ("d" 277 285)
  82.     ("e" 286 292)
  83.     ("f" 293 298)
  84.     ("g" 299 306)
  85.     ("h" 307 315)
  86.     ("i" 316 320)
  87.     ("j" 321 324)
  88.     ("k" 325 333)
  89.     ("l" 334 338)
  90.     ("m" 339 351)
  91.     ("n" 352 360)
  92.     ("o" 361 368)
  93.     ("p" 369 377)
  94.     ("q" 378 386)
  95.     ("r" 387 393)
  96.     ("s" 394 399)
  97.     ("t" 400 405)
  98.     ("u" 406 414)
  99.     ("v" 415 423)
  100.     ("w" 424 436)
  101.     ("x" 437 444)
  102.     ("y" 445 453)
  103.     ("z" 454 460)
  104.     ("0" 461 467)
  105.     ("1" 468 472)
  106.     ("2" 473 479)
  107.     ("3" 480 486)
  108.     ("4" 487 493)
  109.     ("5" 494 500)
  110.     ("6" 501 507)
  111.     ("7" 508 514)
  112.     ("8" 515 521)
  113.     ("9" 522 528)
  114.     ("`" 529 531)
  115.     ("~" 532 538)
  116.     ("!" 539 541)
  117.     ("@" 542 552)
  118.     ("#" 553 560)
  119.     ("$" 561 567)
  120.     ("%" 568 580)
  121.     ("^" 581 586)
  122.     ("&" 587 597)
  123.     ("*" 598 603)
  124.     ("(" 604 608)
  125.     (")" 609 613)
  126.     ("-" 614 620)
  127.     ("_" 621 628)
  128.     ("=" 629 635)
  129.     ("+" 636 643)
  130.     ("[" 644 648)
  131.     ("{" 649 653)
  132.     ("]" 654 658)
  133.     ("}" 659 663)
  134.     (";" 664 666)
  135.     (":" 667 669)
  136.     ("'" 670 672)
  137.     ("\"" 673 676)
  138.     ("," 677 679)
  139.     ("<" 680 686)
  140.     ("." 687 689)
  141.     (">" 690 696)
  142.     ("/" 697 700)
  143.     ("?" 701 707)
  144.     ("\\" 708 713)
  145.     ("|" 714 715)
  146.     (" " 716 719))
  147.   "Indices into the xpm-button-font-pixel-lines strings for each character.
  148. Format is
  149.   (STR START END)
  150. STR contains the character.
  151. START is where the character's pixels start in each string of
  152.    xpm-button-font-pixel-lines (0 is the index of the first pixel).
  153. END is the index of the position after the last pixel of the character.")
  154.  
  155. (defun xpm-button-lookup-rgb-components (color)
  156.   "Lookup COLOR (a color name) in rgb.txt and return a list of RGB values.
  157. The list (R G B) is returned, or an error is signaled if the lookup fails."
  158.   (let ((lib-list x-library-search-path)
  159.     file r g b)
  160.     (while lib-list
  161.       (setq file (expand-file-name "rgb.txt" (car lib-list)))
  162.       (if (file-readable-p file)
  163.       (setq lib-list nil)
  164.     (setq lib-list (cdr lib-list)
  165.           file nil)))
  166.     (if (null file)
  167.     (error "xpm-button-lookup-rgb-components: Can't find rgb.txt file.")
  168.       (save-excursion
  169.     (set-buffer (find-file-noselect file))
  170.     (save-excursion
  171.       (save-restriction
  172.         (widen)
  173.         (goto-char (point-min))
  174.         (or (re-search-forward (format "\t%s$" (regexp-quote color)) nil t)
  175.         (error "No such color: %s"))
  176.         (beginning-of-line)
  177.         (setq r (* (read (current-buffer)) 256)
  178.           g (* (read (current-buffer)) 256)
  179.           b (* (read (current-buffer)) 256))
  180.         (list r g b) ))))))
  181.  
  182. (defun xpm-button-hex-string-to-number (string)
  183.   "Convert STRING to an integer by parsing it as a hexadecimal number."
  184.   (let ((conv-list '((?0 . 0) (?a . 10) (?A . 10)
  185.              (?1 . 1) (?b . 11) (?B . 11)
  186.              (?2 . 2) (?c . 12) (?C . 12)
  187.              (?3 . 3) (?d . 13) (?D . 13)
  188.              (?4 . 4) (?e . 14) (?E . 14)
  189.              (?5 . 5) (?f . 15) (?F . 15)
  190.              (?6 . 6) 
  191.              (?7 . 7)
  192.              (?8 . 8)
  193.              (?9 . 9)))
  194.     (n 0)
  195.     (i 0)
  196.     (lim (length string)))
  197.     (while (< i lim)
  198.       (setq n (+ (* n 16) (or (cdr (assq (aref string i) conv-list)) 0))
  199.         i (1+ i)))
  200.     n ))
  201.  
  202. (defun xpm-button-parse-rgb-components (color)
  203.   "Parse RGB color specification and return a list of integers (R G B).
  204. #FEFEFE and rgb:fe/fe/fe style specifications are parsed."
  205.   (let ((case-fold-search t)
  206.     r g b str)
  207.   (cond ((string-match "^#[0-9a-f]+$" color)
  208.      (cond
  209.       ((= (length color) 4)
  210.        (setq r (xpm-button-hex-string-to-number (substring color 1 2))
  211.          g (xpm-button-hex-string-to-number (substring color 2 3))
  212.          b (xpm-button-hex-string-to-number (substring color 3 4))
  213.          r (* r 4096)
  214.          g (* g 4096)
  215.          b (* b 4096)))
  216.       ((= (length color) 7)
  217.        (setq r (xpm-button-hex-string-to-number (substring color 1 3))
  218.          g (xpm-button-hex-string-to-number (substring color 3 5))
  219.          b (xpm-button-hex-string-to-number (substring color 5 7))
  220.          r (* r 256)
  221.          g (* g 256)
  222.          b (* b 256)))
  223.       ((= (length color) 10)
  224.        (setq r (xpm-button-hex-string-to-number (substring color 1 4))
  225.          g (xpm-button-hex-string-to-number (substring color 4 7))
  226.          b (xpm-button-hex-string-to-number (substring color 7 10))
  227.          r (* r 16)
  228.          g (* g 16)
  229.          b (* b 16)))
  230.       ((= (length color) 13)
  231.        (setq r (xpm-button-hex-string-to-number (substring color 1 5))
  232.          g (xpm-button-hex-string-to-number (substring color 5 9))
  233.          b (xpm-button-hex-string-to-number (substring color 9 13))))
  234.       (t (error "Invalid RGB color specification: %s" color))))
  235.     ((string-match "rgb:\\([0-9a-f]+\\)/\\([0-9a-f]+\\)/\\([0-9a-f]+\\)"
  236.                color)
  237.      (if (or (> (- (match-end 1) (match-beginning 1)) 4)
  238.          (> (- (match-end 2) (match-beginning 2)) 4)
  239.          (> (- (match-end 3) (match-beginning 3)) 4))
  240.          (error "Invalid RGB color specification: %s" color)
  241.        (setq str (match-string 1 color)
  242.          r (* (xpm-button-hex-string-to-number str)
  243.               (expt 16 (- 4 (length str))))
  244.          str (match-string 2 color)
  245.          g (* (xpm-button-hex-string-to-number str)
  246.               (expt 16 (- 4 (length str))))
  247.          str (match-string 3 color)
  248.          b (* (xpm-button-hex-string-to-number str)
  249.               (expt 16 (- 4 (length str)))))))
  250.     (t (error "Invalid RGB color specification: %s" color)))
  251.   (list r g b) ))
  252.  
  253. (defun xpm-button-color-rgb-components (color)
  254.   "Return the RGB components of COLOR as a list of integers (R G B).
  255. 16-bit values are always returned.
  256. #FEFEFE and rgb:fe/fe/fe style color specifications are parsed directly
  257. into their components.
  258. RGB values for color names are looked up in the rgb.txt file.
  259. The variable x-library-search-path is use to locate the rgb.txt file."
  260.   (if (let ((case-fold-search t))
  261.     (or (string-match "^#" color)
  262.         (string-match "^rgb:" color)))
  263.       (xpm-button-parse-rgb-components color)
  264.     (xpm-button-lookup-rgb-components color)))
  265.  
  266. (defun xpm-button-compute-contrast-color (color)
  267.   "Compute a contrasting color for COLOR.
  268. The new color is created by xor-ing the RGB values of COLOR with all ones."
  269.   (let* ((rgb (xpm-button-color-rgb-components color))
  270.      (r (logxor (nth 0 rgb) 65535))
  271.      (g (logxor (nth 1 rgb) 65535))
  272.      (b (logxor (nth 2 rgb) 65535)))
  273.     (format "rgb:%04x/%04x/%04x" r g b)))
  274.  
  275. (defun xpm-button-compute-shadow-colors (color)
  276.   "Compute shadow colors for COLOR.
  277. COLOR should be a string naming a color.
  278. Returns (COLOR1 . COLOR2) where COLOR1 is the brighter shadow color
  279. and COLOR2 is the dimmer color."
  280.   (let* ((rgb (xpm-button-color-rgb-components color))
  281.      (r (nth 0 rgb))
  282.      (g (nth 1 rgb))
  283.      (b (nth 2 rgb))
  284.      (bright-r (/ (* r 12) 10))
  285.      (bright-g (/ (* g 12) 10))
  286.      (bright-b (/ (* b 12) 10))
  287.      (dim-r (/ (* r 8) 10))
  288.      (dim-g (/ (* g 8) 10))
  289.      (dim-b (/ (* b 8) 10)))
  290.     (if (> bright-r 65535)
  291.     (setq bright-r 65535))
  292.     (if (> bright-g 65535)
  293.     (setq bright-g 65535))
  294.     (if (> bright-b 65535)
  295.     (setq bright-b 65535))
  296.     (cons (format "rgb:%04x/%04x/%04x" bright-r bright-g bright-b)
  297.       (format "rgb:%04x/%04x/%04x" dim-r dim-g dim-b))))
  298.  
  299. (defun xpm-button-create (text shadow-thickness fg-color bg-color)
  300.   "Returns a list of XPM image instantiators for a button displaying TEXT.
  301. The list is of the form
  302.    (UP DOWN DISABLED)
  303. where UP, DOWN, and DISABLED are the up, down and disabled image
  304. instantiators for the button.
  305.  
  306. SHADOW-THICKNESS specifies how many pixels should be used for the
  307. shadows on the edges of the buttons.  It should be a positive integer,
  308. or 0 to mean no shadows on the edges.
  309. FG-COLOR is the color used to display the text.  It should be a string.
  310. BG-COLOR is the background color the text will be displayed upon.
  311. It should be a string."
  312.   (save-excursion
  313.     (set-buffer (get-buffer-create " xpm-button"))
  314.     (erase-buffer)
  315.     ;; create the correct number of lines for the pixels for the
  316.     ;; characters.
  317.     (insert-char ?\n (length xpm-button-font-pixel-lines))
  318.     (let ((i 0)
  319.       (str (make-string 1 0))
  320.       (lim (length text))
  321.       (bg-char ? )
  322.       font-pixel-lines q)
  323.       ;; loop through text, adding the character pixels
  324.       (while (< i lim)
  325.     (aset str 0 (aref text i))
  326.     (if (null (setq q (assoc str xpm-button-font-line-indices)))
  327.         nil ; no pixel data for this character
  328.       (goto-char (point-min))
  329.       (setq font-pixel-lines xpm-button-font-pixel-lines)
  330.       (while font-pixel-lines
  331.         (end-of-line)
  332.         (if (not (bolp))
  333.         ;; Insert space before some of the characters.
  334.         ;; This isn't really correct for this font
  335.         ;; but doing it right is too hard.
  336.         ;; This isn't TeX after all.
  337.         (if (memq (aref str 0) '(?, ?. ?\" ?! ?| ?\' ?\`))
  338.             (insert-char bg-char 1))
  339.           ;; offset the start a bit from the left edge of the button
  340.           (insert-char bg-char xpm-button-horizontal-padding))
  341.         ;; insert the character pixels.
  342.         (insert (substring (car font-pixel-lines) (nth 1 q) (nth 2 q)))
  343.         (forward-line)
  344.         (setq font-pixel-lines (cdr font-pixel-lines))))
  345.     (setq i (1+ i)))
  346.       ;; now offset the text from the right edge of the button.
  347.       (goto-char (point-min))
  348.       (while (not (eobp))
  349.     (end-of-line)
  350.     (insert-char bg-char xpm-button-horizontal-padding)
  351.     (forward-line)))
  352.     (let ((bright-char ?b)
  353.       (dim-char ?d)
  354.       (fg-char ?x)
  355.       (bg-char ? )
  356.       (shadow-colors (xpm-button-compute-shadow-colors bg-color))
  357.       i len up-string down-string disabled-string)
  358.       ;; find the length of a pixel line.
  359.       (goto-char (point-min))
  360.       (end-of-line)
  361.       (setq len (- (point) (point-min)))
  362.       ;; offset text from the top of the button
  363.       (goto-char (point-min))
  364.       (setq i xpm-button-vertical-padding)
  365.       (while (> i 0)
  366.     (insert-char bg-char len)
  367.     (insert ?\n)
  368.     (setq i (1- i)))
  369.       ;; offset text from the bottom of the button
  370.       (goto-char (point-max))
  371.       (setq i xpm-button-vertical-padding)
  372.       (while (> i 0)
  373.     (insert-char bg-char len)
  374.     (insert ?\n)
  375.     (setq i (1- i)))
  376.       ;; add shadows to the pixel lines
  377.       (goto-char (point-min))
  378.       (while (not (eobp))
  379.     (insert-char bright-char shadow-thickness)
  380.     (end-of-line)
  381.     (insert-char dim-char shadow-thickness)
  382.     (forward-line))
  383.       ;; add top and bottom shadow lines
  384.       (setq i shadow-thickness)
  385.       (goto-char (point-min))
  386.       (while (> i 0)
  387.     (insert-char bright-char (+ len shadow-thickness i))
  388.     (insert-char dim-char (- shadow-thickness i))
  389.     (insert ?\n)
  390.     (setq i (1- i)))
  391.       (setq i shadow-thickness)
  392.       (goto-char (point-max))
  393.       (while (> i 0)
  394.     (insert-char bright-char i)
  395.     (insert-char dim-char (+ len (* 2 shadow-thickness) (- i)))
  396.     (insert ?\n)
  397.     (setq i (1- i)))
  398.       ;; add doublequotes, commas and XPM header goop.
  399.       (goto-char (point-min))
  400.       (while (not (eobp))
  401.     (insert "\"")
  402.     (end-of-line)
  403.     (insert "\",")
  404.     (forward-line))
  405.       (insert "};\n")
  406.       (goto-char (point-min))
  407.       ;; color map for the UP button
  408.       (insert (format
  409.            "/* XPM */
  410. static char * button_xpm[] = {
  411. \"%d %d 4 1\",
  412. \"%c   c %s\",
  413. \"%c   c %s\",
  414. \"%c   c %s\",
  415. \"%c   c %s\",
  416. "
  417.            (+ len (* shadow-thickness 2))
  418.            (+ (* xpm-button-vertical-padding 2)
  419.           (* shadow-thickness 2)
  420.           (length xpm-button-font-pixel-lines))
  421.            fg-char fg-color
  422.            bg-char bg-color
  423.            bright-char (car shadow-colors)
  424.            dim-char (cdr shadow-colors)))
  425.       (setq up-string (buffer-string))
  426.       (delete-region (point-min) (point))
  427.       ;; color map for the DOWN button
  428.       (insert (format
  429.            "/* XPM */
  430. static char * button_xpm[] = {
  431. \"%d %d 4 1\",
  432. \"%c   c %s\",
  433. \"%c   c %s\",
  434. \"%c   c %s\",
  435. \"%c   c %s\",
  436. "
  437.            (+ len (* shadow-thickness 2))
  438.            (+ (* xpm-button-vertical-padding 2)
  439.           (* shadow-thickness 2)
  440.           (length xpm-button-font-pixel-lines))
  441.            fg-char (xpm-button-compute-contrast-color fg-color)
  442.            bg-char bg-color
  443.            bright-char (cdr shadow-colors)
  444.            dim-char (car shadow-colors)))
  445.       (setq down-string (buffer-string))
  446.       (delete-region (point-min) (point))
  447.       ;; color map for the DISABLED button
  448.       (insert (format
  449.            "/* XPM */
  450. static char * button_xpm[] = {
  451. \"%d %d 4 1\",
  452. \"%c   c %s\",
  453. \"%c   c %s\",
  454. \"%c   c %s\",
  455. \"%c   c %s\",
  456. "
  457.            (+ len (* shadow-thickness 2))
  458.            (+ (* xpm-button-vertical-padding 2)
  459.           (* shadow-thickness 2)
  460.           (length xpm-button-font-pixel-lines))
  461.            fg-char fg-color
  462.            bg-char bg-color
  463.            bright-char (car shadow-colors)
  464.            dim-char (cdr shadow-colors)))
  465.       ;; stipple the foreground pixels
  466.       (let ((str (make-string 1 0))
  467.         (bit 0)
  468.         lim line-start)
  469.     (aset str 0 fg-char)
  470.     (while (not (eobp))
  471.       (setq lim (save-excursion (end-of-line) (point))
  472.         line-start (point))
  473.       (while (search-forward str lim t)
  474.         (if (= (% (- (point) line-start) 2) bit)
  475.         (subst-char-in-region (1- (point)) (point) fg-char bg-char t)))
  476.       (if (zerop bit)
  477.           (setq bit 1)
  478.         (setq bit 0))
  479.       (forward-line)))
  480.       (setq disabled-string (buffer-string))
  481.  
  482.       (list (vector 'xpm ':data up-string)
  483.         (vector 'xpm ':data down-string)
  484.         (vector 'xpm ':data disabled-string)) )))
  485.